﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace WindowsStoreWRC
{
    public sealed class WRCServiceCom
    {
        #region Pesquisa de Programas
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sTexto"></param>
        /// <returns></returns>
        async private static Task<string> buscaProgramasWS(string pTextoPesquisa, string pPagina, string pPorPagina)
        {
            return await Task.Run(async () =>
            {
                var client = new JSONService.JSONServiceSoapClient();
                JSONService.SearchJSONResponse o = await client.SearchJSONAsync(pTextoPesquisa, pPagina, "1", pPorPagina);
                return o.Body.SearchJSONResult;
            });
        }

        public static Windows.Foundation.IAsyncOperation<string> buscaProgramas(string pTextoPesquisa, string pPagina, string pPorPagina)
        {
            return buscaProgramasWS(pTextoPesquisa, pPagina, pPorPagina).AsAsyncOperation();
        }
        #endregion

        #region Dados do Programa
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sTexto"></param>
        /// <returns></returns>
        async private static Task<string> dadosProgramaWS(string pIdfPrograma)
        {
            return await Task.Run(async () =>
            {
                var client = new JSONService.JSONServiceSoapClient();
                JSONService.GetProgramDataJSONResponse o = await client.GetProgramDataJSONAsync(pIdfPrograma);
                return o.Body.GetProgramDataJSONResult;
            });
        }

        public static Windows.Foundation.IAsyncOperation<string> dadosPrograma(string pIdfPrograma)
        {
            return dadosProgramaWS(pIdfPrograma).AsAsyncOperation();
        }
        #endregion

        #region Top Downloads
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sTexto"></param>
        /// <returns></returns>
        async private static Task<string> listarTopDownloadsWS()
        {
            return await Task.Run(async () =>
            {
                var client = new JSONService.JSONServiceSoapClient();
                JSONService.TopGeralJSONResponse o = await client.TopGeralJSONAsync(string.Empty, "Download", "1", "1", "100");
                return o.Body.TopGeralJSONResult;
            });
        }

        public static Windows.Foundation.IAsyncOperation<string> listarTopDownloads()
        {
            return listarTopDownloadsWS().AsAsyncOperation();
        }
        #endregion
    }
}
